package com.hhh.springai_test.controller;

import com.hhh.springai_test.common.BaseResponse;
import com.hhh.springai_test.common.ResultUtils;
import com.hhh.springai_test.service.BannerService;
import com.hhh.springai_test.model.dto.AddBannerDTO;
import com.hhh.springai_test.model.dto.UpdateBannerDTO;
import com.hhh.springai_test.model.po.Banner;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import cn.dev33.satoken.annotation.SaCheckRole;
import jakarta.validation.Valid;
import com.hhh.springai_test.constant.UserConstant;
import java.util.List;

@RestController
@RequestMapping("/banner")
public class BannerController {

    @Resource
    private BannerService bannerService;

    @PostMapping("/add")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> addBanner(@RequestBody @Valid AddBannerDTO addBannerDTO) {
        Boolean isSuccess = bannerService.addBanner(addBannerDTO);
        return ResultUtils.success(isSuccess);
    }

    @PutMapping("/update")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> updateBanner(@RequestBody @Valid UpdateBannerDTO updateBannerDTO) {
        Boolean isSuccess = bannerService.updateBanner(updateBannerDTO);
        return ResultUtils.success(isSuccess);
    }

    @DeleteMapping("/delete/{id}")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> deleteBanner(@PathVariable Long id) {
        Boolean isSuccess = bannerService.deleteBanner(id);
        return ResultUtils.success(isSuccess);
    }

    @GetMapping("/list")
    public BaseResponse<List<Banner>> listBanner() {
        List<Banner> bannerList = bannerService.listBanner();
        return ResultUtils.success(bannerList);
    }
}
